﻿package zf.media.audio.spectrum
{
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Matrix;
	import flash.display.GradientType;

	import flash.filters.GlowFilter;

	import zf.media.audio.SoundSpectrumMode;
	/**
	 * 直线频谱类 
	 * @author mike.zhang
	 * 
	 */
	public class LineSpectrum extends SoundSpectrum
	{
		private var lineSprite:Sprite;
		/**
		 * 创建一个直线频谱图形 
		 * @param w 宽度
		 * @param h 高度
		 * 
		 */
		public function LineSpectrum (w:Number,h:Number):void
		{
			super (w,h);
			type=SoundSpectrumMode.LS;
			lineSprite=new Sprite;
			ff=Math.floor((w/128))*16;
			ff=ff>16?ff:16;
			ff=ff<128?ff:128;
			//addChild(lineSprite);
			//lineSprite.filters=new Array(new GlowFilter(getCt().color,1,4,4,4));
		}
		/**
		 * @private 
		 * 
		 */
		override protected function draw ():void
		{
			super.draw ();
			//var _bg.bitmapData:BitmapData=_bg.bitmapData;
			//_bg.bitmapData.draw (lineSprite);//将效果容器中的图像复制
			//_bg.bitmapData.applyFilter (_bg.bitmapData, _bg.bitmapData.rect, new Point(), new GlowFilter(0xFFFFFF,1,4,4,4));//应用模糊滤镜
			//addChild(lineSprite);
			lineSprite.graphics.clear ();
			var i:uint=0;
			var headH:Number=5;
			var ivt:Number=ww/(ff+1);
			var hs:Number=hh-headH*2;
			var n:Number;

			var gradientBoxMatrix:Matrix=new Matrix;
			gradientBoxMatrix.createGradientBox (ww,hs,270*Math.PI/180,0,0);
			lineSprite.graphics.lineStyle (1.5);
			lineSprite.graphics.lineGradientStyle(GradientType.LINEAR, [0xFFFFFF,0xFFFF00, 0xFF0000], [1, 1, 1], [0, 64, 128], gradientBoxMatrix);
			for (i=0; i<ff/2; i++)
			{
				n=Math.abs(byArr[i])*hs*1.8;
				lineSprite.graphics.moveTo ((i+1)*ivt,hs);
				lineSprite.graphics.lineTo ((i+1)*ivt,hs-n);

				//graphics.moveTo ((i+1)*ivt,hh-n-3);
				//graphics.lineTo ((i+1)*ivt,hh-n-4);
			}
			//graphics.lineStyle (2,0x0000ff);
			var k:uint=ff/2;
			for (i=ff-1; i>=ff/2; i--)
			{
				n=Math.abs(byArr[i])*hs*1.8;
				lineSprite.graphics.moveTo ((k+1)*ivt,hs);
				lineSprite.graphics.lineTo ((k+1)*ivt,hs-n);

				//graphics.moveTo ((k+1)*ivt,hs-n-3);
				//graphics.lineTo ((k+1)*ivt,hs-n-4);
				k++;
			}
			
			_bg.bitmapData.draw (lineSprite,null,null,_blendMode);
			_bg.bitmapData.applyFilter (_bg.bitmapData,_bg.bitmapData.rect,new Point(),new BlurFilter(2,2,1));
			//_bg.bitmapData.colorTransform (_bg.bitmapData.rect,randomCt);
			_bg.bitmapData.colorTransform (_bg.bitmapData.rect,new ColorTransform(1, 1, 1, 1, -5, -10, -10));
			_bg.bitmapData.scroll (0,1);
		}
		override public function defaultConfig():void
		{
			abs=false;
			machining=false;
		}
	}
}